<!doctype html>
<html >

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
					<a id="refreshhtml" class="mui-icon mui-pull-left">刷新</a>
					<h1 class="mui-title">叶子</h1>
					<a  id="backlogin" class=" mui-icon  mui-pull-right">退出登录</a>
				</header>
				<div class="mui-content" style="margin: 0 auto;">
					<div class="" style="text-align: left; font-size: large;margin-top: 50px;">
						<ul class="mui-table-view" id="user" style="background-color: rgb(239, 239, 244);">
								<li class="mui-table-view-cell">
									账号:{{user.mobile}}
								</li>
								<li class="mui-table-view-cell">
									金额:{{user.totalRecharge}}
								</li>
								<li class="mui-table-view-cell">
									余额:{{user.balance}}
								</li>
								<li class="mui-table-view-cell">
									等级:{{user.lev}}
								</li>
								<li class="mui-table-view-cell">
									扫码个数:{{user.overCodeNum}}
								</li>
								<li class="mui-table-view-cell">
									<input type="number" id='money' placeholder="请输入提现金额,手续费百分之十" style="width: 80%;">
									<button type="button" id="extract" class="mui-btn mui-btn-blue " style="margin-top: -8px;">提现</button>
								</li>
								<li class="mui-table-view-cell">
									客服微信:{{user.weixin}}
								</li>
								<li class="mui-table-view-cell">
									<input type="text" id='shareurl' hidden="hidden" value=""  style="width: 80%;">
									分享：<span  id="copyUrl" style="color: #007AFF;"> 点击获取注册链接</span>
								</li>
							</ul>
					</div>
					
					
				</div>
		
				<nav class="mui-bar mui-bar-tab">
					<a id="defaultTab" class="mui-tab-item mui-active" href="index.html">
						<span class="mui-icon mui-icon-videocam"></span>
						<span class="mui-tab-label">节能社区</span>
					</a>
					<a class="mui-tab-item" href="index2.html">
						<span class="mui-icon mui-icon-chatboxes">
							<!-- <span class="mui-badge">9</span> -->
						</span>
						<span class="mui-tab-label">排名与奖励</span>
					</a>
					<a class="mui-tab-item" href="index3.html">
						<span class="mui-icon mui-icon-home"></span>
						<span class="mui-tab-label">我的</span>
					</a>
				</nav>
		
		<script src="js/mui.js"></script>
		<script src="js/app.js"></script>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
		  (function($, doc) {
				var vm=new Vue({
				  el: '#user',
				  data: {
				    user: {}
				  }
				})
		 		vm.user={};
		 		var userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
		 		console.log("token:"+userinfo.access_token)
		 		var backlogin = doc.getElementById('backlogin');
		 		var extract = doc.getElementById('extract');
		 		var copyUrl = doc.getElementById('copyUrl');
		 		inituser();
		 		function inituser(){
		 			$.ajax(api+'/user/getUser',{
		 				data:{
							access_token:userinfo.access_token
		 				},
		 				dataType:'json',//服务器返回json格式数据
		 				crossDomain:true,
		 				cache:true,
		 				type:'GET',//HTTP请求类型
		 				timeout:10000,//超时时间设置为10秒；data
		 				  beforeSend: function(request) {
		 					    // request.setRequestHeader("Content-Type",'application/json');
		 					   	// request.setRequestHeader("access_token", userinfo.access_token);
		 					  },
		 				success:function(data){
		 					console.log(JSON.stringify(data))
		 					if(data.code==1){
		 						var resdata=data.data;
		 						resdata.weixin=userinfo.weixin;
		 						vm.user=resdata;
		 						// this.$set(this.user,'user',data.data)
		 					}else{
		 						$.toast(data.msg)
		 					}
		 				},
		 				error:function(xhr,type,errorThrown){
		 					//异常处理；
		 					$.toast("系统异常")
							
		 					
		 				}
		 			});
		 		}
		 		copyUrl.addEventListener('tap',function(){
		 			console.log("copy")
		 			console.log(JSON.stringify(userinfo))
					if(vm.user.lev<1){
						$.toast("等级大于0级才能推广")
						return ;
					}
		 			copyText();
		 		});
				extract.addEventListener('tap',function(){
					  var mon=document.getElementById('money').value;
					  console.log(mon)
					  if(mon<10){
						  $.toast("超过十元才能提现")
						  return ;
					  }
					   console.log(mon.toString())
				 	$.ajax(api+'/user/extract',{
				 		data:{
							money : mon.toString(),
							access_token:userinfo.access_token
				 		},
				 		dataType:'json',//服务器返回json格式数据
				 		crossDomain:true,
				 		cache:true,
				 		type:'get',//HTTP请求类型
				 		timeout:10000,//超时时间设置为10秒；data
				 		
				 		  beforeSend: function(request) {
				 			  console.log(userinfo.refreshToken)
				 					 //   request.setRequestHeader("Content-Type",'application/json');
				 						// request.setRequestHeader("access_token", userinfo.access_token);
				 					  },
				 		success:function(data){
				 			console.log(JSON.stringify(data))
				 			if(data.code==1){
				 				// var thisView = plus.webview.currentWebview().opener();
				 				//  $.fire(thisView, 'refresh');
								 location.reload() 
				 			}else{
				 				$.toast(data.msg)
				 			}
				 			
							
				 		},
				 		error:function(xhr,type,errorThrown){
				 			//异常处理；
				 			$.toast("系统异常")
				 		}
				 	});
				 
				  })
				 
		
				
				function copyText(event){
									  console.log(userinfo.id)
					const text=apireg+'/reg1.html?pid='+(userinfo.id||'')
				  // 数字没有 .length 不能执行selectText 需要转化成字符串
				  const textString = text.toString();
				  let input = document.querySelector('#copy-input');
				  if (!input) {
				    input = document.createElement('input');
				    input.id = "copy-input";
				    input.readOnly = "readOnly";        // 防止ios聚焦触发键盘事件
				    input.style.position = "absolute";
				    input.style.left = "-1000px";
				    input.style.zIndex = "-1000";
				    document.body.appendChild(input)
				  }
						 
				  input.value = textString;
				  // ios必须先选中文字且不支持 input.select();
				  selectText(input, 0, textString.length);
				  if (document.execCommand('copy')) {
				    document.execCommand('copy');
				    $.toast('已复制到粘贴板');
				  }else {
				    $.toast('不兼容');
				  }
				  input.blur();
						 
				  // input自带的select()方法在苹果端无法进行选择，所以需要自己去写一个类似的方法
				  // 选择文本。createTextRange(setSelectionRange)是input方法
				  function selectText(textbox, startIndex, stopIndex) {
				    if (textbox.createTextRange) {//ie
				      const range = textbox.createTextRange();
				      range.collapse(true);
				      range.moveStart('character', startIndex);//起始光标
				      range.moveEnd('character', stopIndex - startIndex);//结束光标
				      range.select();//不兼容苹果
				    } else {//firefox/chrome
				      textbox.setSelectionRange(startIndex, stopIndex);
				      textbox.focus();
				    }
				  }
				};
		 			
		 
			
		  }(mui, document));
		</script>
		
		
		
	</body>

</html>
